var brandList, pbcList;

$(function () {

    //录入承运方
    $("[name='btn_save_new_product']").click(function () {
        var form = window.form_new_product;
        
        var name = form.name.value;
        var website = form.website.value;
        

        /*if (name == null) {
            bootbox.balert("公司名称不能为空!");
            return;
        }*/

        var logistics = {name: name, website: website};
        $.postJsonBody("/logisticscompany", logistics, function (re) {
            // tipper.success("已保存，请刷新页面");
            // $("#md_new_brand").modal("hide");
        	window.location.href=window.location.href; 
        	window.location.reload; 
        })
    });

    //编辑保存承运方
    $("[name='btn_save_edit_product']").click(function () {
        var form = window.form_edit_product;
        var id = form.id.value;
        var name = form.name.value;
        var website = form.website.value;
        
        if (name == null || name == '') {
            bootbox.balert("承运公司名称不能为空");
            return;
        }
        if(!website){
        	bootbox.balert("承运公司官网不能为空");
            return;
        }

        var logistics = {id: id, name: name, website: website};
        $.putJsonBody("/logisticscompany/" + id, logistics, function (re) {
            // tipper.success("已保存，请刷新页面");
            // $("#md_new_brand").modal("hide");
        	window.location.href=window.location.href; 
        	window.location.reload; 
        })
    });

    //删除承运方
    $("[name='btn_delete_product']").click(function () {
        var id = $(this).data("logistics-id");
        bootbox.bconfirm("确定要删除这个承运方吗？", function (re) {
            if (re) {
                $.delete("/logisticscompany/" + id, function (re) {
                    if (re.data) {
                        // tipper.success("删除成功，请刷新页面");
                    	window.location.href=window.location.href; 
                    	window.location.reload; 
                    } else {
                        tipper.danger("删除失败，请重试");
                    }
                });
            }
        });
    });
});


// 承运方详情
$('#md_edit_product').on('show.bs.modal', function (event) {
    var _e = $(event.relatedTarget);
    var id = _e.data("logistics-id");
    var name = _e.data("logistics-name");
    var modal = $(this);
    var form = window.form_edit_product;
    name = encodeURI(encodeURI(name));
    $.get("/logisticscompany/" + name + "/" + id, function (re) {
        var logistics = re.data;
        form.id.value = logistics.id;
        form.name.value = logistics.name;
        form.website.value = logistics.website;
    });
});

//查询条件重置
$("#search_reset").click(function(){
	$("input").val("");
    $("select").val("");
});
